package com.zxx.pattern.statePattern.state;

/**
 * 糖果机类
 *
 * @author zxx on 2021/1/14
 */
public class CandyMachine {

    private State moneyInsertedState;
    private State noMoneyState;
    private State noCandyState;
    private State candyPoppingState;
    private State winnerState;

    private State state;
    private int candyCount;

    public CandyMachine(int candyCount) {
        this.candyCount = candyCount;
        this.moneyInsertedState = new StateMoneyInserted(this);
        this.noMoneyState = new StateNoMoney(this);
        this.noCandyState = new StateNoCandy(this);
        this.candyPoppingState = new StateCandyPopping(this);
        this.winnerState = new StateWinner(this);
        this.state = noMoneyState;
    }

    //投币
    public void insertMoney(){
        this.state.onMoneyInserted();
    }

    //退钱
    public void returnMoney(){
        this.state.onMoneyReturned();
    }

    //转动摇把
    public void turnCrank(){
        this.state.onCrankTurned();
    }

    //发糖果
    public void popCandy(){
        this.state.onCandyPoped();
    }

    //------------可以修改初始状态的 设置状态----------------------------
    public State getMoneyInsertedState() {
        return moneyInsertedState;
    }

    public void setMoneyInsertedState(State moneyInsertedState) {
        this.moneyInsertedState = moneyInsertedState;
    }

    public State getNoMoneyState() {
        return noMoneyState;
    }

    public void setNoMoneyState(State noMoneyState) {
        this.noMoneyState = noMoneyState;
    }

    public State getNoCandyState() {
        return noCandyState;
    }

    public void setNoCandyState(State noCandyState) {
        this.noCandyState = noCandyState;
    }

    public State getCandyPoppingState() {
        return candyPoppingState;
    }

    public void setCandyPoppingState(State candyPoppingState) {
        this.candyPoppingState = candyPoppingState;
    }

    public State getWinnerState() {
        return winnerState;
    }

    public void setWinnerState(State winnerState) {
        this.winnerState = winnerState;
    }
    //------------可以修改初始状态的 设置状态End----------------------------


    //-------------切换状态----------------------
    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public int getCandyCount() {
        return candyCount;
    }

    public void setCandyCount(int candyCount) {
        this.candyCount = candyCount;
    }
}
